<template>
  <customDrawer :title="'批量设置' + setType + '属性'" ref="customDrawerSetBatch"
                :widthPx="500" :heightPx="500"
                @confirm="customDrawerSetBatchConfirm"
                :autoHide="false"

  >
    <template #content v-if="isRender">
      <customForm :data="setForm"  ref="editForm" style="padding: 10px; padding-right: 40px" :label-width="80">
        <template #content>

          <slot name="form" :data="setForm"></slot>
          <customFormItem :label="'已选' + setType" name="nameList" :parent="_self" :form="setForm" :type="constCommon.formItemType.slot.name"
                          fullWidth
          >
            <template #content>
              <span style="    max-height: 200px;overflow: auto;">{{setForm.nameList}}</span>
            </template>
          </customFormItem>
        </template>
      </customForm>
      <div style="padding-left: 20px">
        <strong>维护说明：</strong>
        <br>
        <small>
          1、批量设置所选择的列表数据属性<br>
          2、未指定的属性不做处理<br>
          3、点击【确认】按钮完成批量更新<br>
        </small>
      </div>
    </template>
  </customDrawer>
</template>

<script>
export default {
  desc: '批量设置属性',
  name: 'setBatchWin',
  components: {},
  props: {
    /**
     * @Description： 设置名称
     * @Date 2023-10-10
     */
    setType: {
      type: String,
      default: () => ''
    },
    /**
     * @Description： 设置低值
     * @Date 2023-10-10
     */
    setAction: {
      type: String,
      default: () => ''
    }
  },
  mounted() {
  },
  data() {
    return {
      setForm: {
      },
      isRender: false
    }
  },
  methods: {
    show(data) {
      if (data.length == 0) {
        this.utilMessage.error('请先勾选列表需要操作的商品')
        return false
      }
      this.isRender = true
      this.setForm = {}
      this.$set(this.setForm, 'nameList', data.map(item => item.name).join(','))
      this.$set(this.setForm, 'idList', data.map(item => item.id))
      this.$refs.customDrawerSetBatch.show()
    },
    setFormValue(key ,value) {
      this.$set(this.setForm, key, value)
    },
    customDrawerSetBatchConfirm() {
      let postData = {}
      postData.hasData = false
      postData.idListJoin = this.setForm.idList.join(',')
      let keyNot = ['idList', 'nameList']
      let fieldList = []
      Object.keys(this.setForm).filter(key => !keyNot.includes(key)).forEach(keyFind => {
        if (this.strings.isNotBlank(this.setForm[keyFind])) {
          postData[keyFind] = this.setForm[keyFind]
          postData.hasData = true
          fieldList.push(keyFind)
        }
      })
      if (!postData.hasData) {
        this.utilMessage.warning('至少指定一个需要批量设置的属性')
        return
      }
      postData.fieldListJoin = fieldList.join(',')
      this.utilVue.loadShow(true)
      this.$ajax.post(this.setAction, postData).then(response => {
        this.utilVue.loadHide()
        if (response.code == 0) {
          this.utilMessage.success(response.msg)
          this.$refs.customDrawerSetBatch.hide()
          this.$emit('afterSet')
        }
      })
    }
  },
  watch: {},
  computed: {
  },
}
</script>

<style lang="scss" scoped>

</style>
